<include file="Public/header" /> 
<script src="__PUBLIC__/js/uploadify/jquery.uploadify.min.js"></script>
<!--主窗体-->
<div class="container app">
	<!--左侧菜单-->
		<include file="Public/sidebar" /> 
		<div id="mainCon" class="mainCon">
			<h4>广告图片</h4>
			<div class="bk10"></div>
		
			<form class="form-horizontal form "  action="" method="post" enctype="multipart/form-data" onsubmit="return postrule(this)" >
			
				<input type="hidden" name="rule_id" value="<{$ruleinfo['rule']['id']}>">
				
				<!-- 图文预览 -->
				<div class="marboxleft" style="margin-top:25px;width:100%" >
					<div class="postcontent" style="margin-left:50px;">
						<!-- <div class="arrow"></div> -->
						<span class='product' editid="one" >
							<table class="pro ruletablebox" style="border-radius:0px;">
								<tr>
									<td style="width:600px">
										<div class="upload-file-box" style="width:600px">
											<div class="radio col-sm-5">
												<a class="btn btn-default" id="uploadify">上传图片</a> <span style="margin-top:10px;float:left;color:#999">（仅允许上传1MB以内的图片）</span>
											</div>
											<div id="upload-file-view" class="OneImageBox upload-view">
												<div id="showimg">										
													<if condition="!empty($result[0]['thumb'])">
														<!-- <div style="width:100px;height:100px;border:1px solid #ccc;overflow:hidden;float:left;">
															<img src="<{$result[0]['thumb']}>" style="width:100px;height:100px;float:left;margin:0 auto;padding:5px;">
															<div onclick="removeImg(this);" style="height:30px;width:100%;background:#000;opacity:.6;text-align:center;z-index:3;position:relative;bottom:30px;color:#fff;line-height:30px;float:left;cursor:pointer;">删除</div>
														</div> -->
													</if>
												</div>
											</div>
											<!-- <div id="upload-file-view" class="OneImageBox upload-view">
												<img id="default-img" src="__PUBLIC__/Application/images/notimage.jpg"  />
											</div> -->
										</div>
									</td>
								</tr>
							</table>
						</span>
					</div>
				</div>
				
				<div class="clear"></div>
				<div style="text-align:center">
					<button type="submit" class="btn btn-danger " name="submit" value="保存" style="width:150px;margin-bottom:20px"/>保存</button>
					<input type='hidden' name='delnews'  id='delnews' value=''/>
				</div>

				
			</form>
		</div>
	</div>
</div>
<script>

	//上传图片
	function postrule(curform){
		var newspicture = $('#showimg').html();
		
		if(!newspicture){
			layer.alert('请上传图片');
			return false;
		}

		var url = "<{:U('do_imgadd')}>";
		$.post(url,$(curform).serializeArray(),function(data){
		
			if(data.status == '1'){
				//layer.alert(data.info,{icon: 1});
				window.location.href = "<{:U('lists',array('k'=>10,'sk'=>0))}>";
			}else{
				layer.alert(data.info,{icon: 2});
			}
		});
		return false;
	}
		
	//移除图片
	function removeImg(obj){
		$(obj).parent().remove();
	}
	
	// 文件上传
	$("#uploadify").uploadify({
		'swf'           : '/Public/js/uploadify/uploadify.swf',
		'uploader'      : "<?php echo U('Admin/Gallery/uploadImg');?>",
		'fileTypeExts'	: '*.jpg;*.png;*.gif',
		'width'			: 90,
		'buttonText' : '<a class="btn btn-default" id="uploadify">上传图片</a>',
		'hideButton' : true,
		'multi': false,
		'fileObjName' : 'imgFile',
		'fileSizeLimit' : '1MB',
		'multi'    : true, //开启,多选文件
		'uploadLimit' : 8, //允许上传文件个数
		'onUploadError' : function(back) {
			
		},
		'onUploadStart' : function(file) {

    	},
		'onUploadSuccess' : function(file,data,response) {
			var r = jQuery.parseJSON(data);
			if(r.error == 0){
				var htm = '<div style="width:100px;height:100px;border:1px solid #ccc;overflow:hidden;float:left;margin-bottom:10px;">';
				htm += '<img src="/'+r.imgUrl+'" style="width:100px;height:100px;float:left;margin:0 auto;padding:5px;">';
				htm += '<div onclick="removeImg(this);" style="height:30px;width:100%;background:#000;opacity:.6;text-align:center;z-index:3;position:relative;bottom:30px;color:#fff;line-height:30px;float:left;cursor:pointer;">删除</div>';
				htm += '<input type="hidden" class="img_input" name="newspicture[]" value="/'+r.imgUrl+'"/>';
				htm += '</div>';
				$("#showimg").append(htm);
			}
		},
	
	});	


</script>
<style>
@media screen and (min-width: 1200px) { 
.main-mid>.content{min-height:529px;background:#fff;padding: 10px 35px 80px 35px;} 
} 
@media screen and (max-width: 1100px) { 
.main-mid>.content{min-height:529px;background:#fff;padding: 10px 0px 80px 35px;} 
}

@media screen and (min-width: 1200px) { 
	.appmsg {
		/*position: relative;*/
		overflow: hidden;
		margin-bottom: 20px;
		border: 1px solid #e7e7eb;
		background-color: #fff;
		color: #8d8d8d;
		width:300px;
		float:left;
	}
} 
@media screen and (max-width: 1100px) { 
	.appmsg {
	/*position: relative;*/
	overflow: hidden;
	margin-bottom: 20px;
	border: 1px solid #e7e7eb;
	background-color: #fff;
	color: #8d8d8d;
	width:30%;
	float:left;
	}
}
input.span5{
	width:450px
}
.appmsg_thumb_wrp img {
	width:100%;
	height:100%
}
.mainCon table, #mainCon table th, #mainCon table td{
	border:0px;
}
</style>
